namespace("mk");

mk.Map = function(width, height) {
    this.width = width;
    this.height = height;
    this.canvas = new sg.canvas.Canvas(width, height, "map").append(document.body);
    this.objects = [];
};
mk.Map.prototype.isCollisionX = function (obj) {
    var rect = obj.getRectangle();
    if(rect.x1<=0 || rect.x2>=this.width) {
        return this;
    }
    for(var i=0; i< this.objects.length; i++) {
        var _obj = this.objects[i];
        if(_obj!= obj) {
            var _rect = _obj.getRectangle();
            if((_rect.x1 >= rect.x1 && _rect.x1 <= rect.x2)||(_rect.x2 >= rect.x1 && _rect.x2 <= rect.x2)) {
                   return _obj;
            }
        }
    }
};
mk.Map.prototype.isCollisionY = function(obj) {
    var rect = obj.getRectangle();
    if(rect.y1 <=0 || rect.y2>=this.height) {
        return this;
    }
    for(var i=0; i< this.objects.length; i++) {
        var _obj = this.objects[i];
        if(_obj!= obj) {
            var _rect = _obj.getRectangle();
            if((_rect.y1 >= rect.y1 && _rect.y1 <= rect.y2)||(_rect.y2 >= rect.y1 && _rect.y2 <= rect.y2)) {
                return _obj;
            }
        }
    }
};

